import java.util.Arrays;
import java.util.Scanner;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/12/22 16:37
 * 继续(3n+1)猜想
 * 算法：数学 + 数组
 */
public class _1005 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] nums = new int[101];
        Arrays.fill(nums, 0);
        for (int i = 0; i < n; i++) nums[in.nextInt()] = 1;
        for (int i = 1; i <= 100; i++) {
            if (nums[i] == 0) continue;
            int num = i;
            while (num != 1) {
                if (num % 2 == 0) num /= 2;
                else  num = (3 * num + 1) / 2;
                if (num <= 100) nums[num] = 0;
            }
        }
        String s = "";
        for (int i = 100; i >= 1; i--) if (nums[i] == 1) s += i + " ";
        for (int i = 0; i < s.length() - 1; i++) System.out.print(s.charAt(i));
        System.out.println();
    }
}
